library(tidyverse) # for data cleaning and plotting
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.5 v dplyr 1.0.3
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(lubridate) # for date manipulation
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(openintro) # for the abbr2state() function
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
library(palmerpenguins)# for Palmer penguin data
library(maps) # for map data
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(ggmap) # for mapping points on maps
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(gplots) # for col2hex() function
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
library(RColorBrewer) # for color palettes
library(sf) # for working with spatial data
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(leaflet) # for highly customizable mapping
library(carData) # for Minneapolis police stops data
library(ggthemes) # for more themes (including theme_map())
theme_set(theme_minimal())
# Starbucks locations
Starbucks <- read_csv("https://www.macalester.edu/~ajohns24/Data/Starbucks.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## Brand = col_character(),
## `Store Number` = col_character(),
## `Store Name` = col_character(),
## `Ownership Type` = col_character(),
## `Street Address` = col_character(),
## City = col_character(),
## `State/Province` = col_character(),
## Country = col_character(),
## Postcode = col_character(),
## `Phone Number` = col_character(),
## Timezone = col_character(),
## Longitude = col_double(),
## Latitude = col_double()
## )
starbucks_us_by_state <- Starbucks %>%
filter(Country == "US") %>%
count(`State/Province`) %>%
mutate(state_name = str_to_lower(abbr2state(`State/Province`)))
# Lisa's favorite St. Paul places - example for you to create your own data
favorite_stp_by_lisa <- tibble(
place = c("Home", "Macalester College", "Adams Spanish Immersion",
"Spirit Gymnastics", "Bama & Bapa", "Now Bikes",
"Dance Spectrum", "Pizza Luce", "Brunson's"),
long = c(-93.1405743, -93.1712321, -93.1451796,
-93.1650563, -93.1542883, -93.1696608,
-93.1393172, -93.1524256, -93.0753863),
lat = c(44.950576, 44.9378965, 44.9237914,
44.9654609, 44.9295072, 44.9436813,
44.9399922, 44.9468848, 44.9700727)
)
#COVID-19 data from the New York Times
covid19 <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## date = col_date(format = ""),
## state = col_character(),
## fips = col_character(),
## cases = col_double(),
## deaths = col_double()
## )
If you were not able to get set up on GitHub last week, go here and get set up first. Then, do the following (if you get stuck on a step, don’t worry, I will help! You can always get started on the homework and we can figure out the GitHub piece later):
keep_md: TRUE in the YAML heading. The .md file is a markdown (NOT R Markdown) file that is an interim step to creating the html file. They are displayed fairly nicely in GitHub, so we want to keep it and look at it there. Click the boxes next to these two files, commit changes (remember to include a commit message), and push them (green up arrow).Put your name at the top of the document.
For ALL graphs, you should include appropriate labels.
Feel free to change the default theme, which I currently have set to theme_minimal().
Use good coding practice. Read the short sections on good code with pipes and ggplot2. This is part of your grade!
When you are finished with ALL the exercises, uncomment the options at the top so your document looks nicer. Don’t do it before then, or else you might miss some important warnings and messages.
These exercises will reiterate what you learned in the “Mapping data with R” tutorial. If you haven’t gone through the tutorial yet, you should do that first.
ggmap)Starbucks locations to a world map. Add an aesthetic to the world map that sets the color of the points according to the ownership type. What, if anything, can you deduce from this visualization?world <- get_stamenmap(
bbox = c(left = -180, bottom = -57, right = 179, top = 82.1),
maptype = "terrain",
zoom = 2)
## Source : http://tile.stamen.com/terrain/2/0/0.png
## Source : http://tile.stamen.com/terrain/2/1/0.png
## Source : http://tile.stamen.com/terrain/2/2/0.png
## Source : http://tile.stamen.com/terrain/2/3/0.png
## Source : http://tile.stamen.com/terrain/2/0/1.png
## Source : http://tile.stamen.com/terrain/2/1/1.png
## Source : http://tile.stamen.com/terrain/2/2/1.png
## Source : http://tile.stamen.com/terrain/2/3/1.png
## Source : http://tile.stamen.com/terrain/2/0/2.png
## Source : http://tile.stamen.com/terrain/2/1/2.png
## Source : http://tile.stamen.com/terrain/2/2/2.png
## Source : http://tile.stamen.com/terrain/2/3/2.png
ggmap(world) +
geom_point(data = Starbucks,
aes(x = Longitude, y = Latitude, color= `Ownership Type`),
alpha = .3,
size = .1) +
theme_map() +
theme(legend.background = element_blank())+
ggtitle("Starbucks locations in the world by Ownership Type")
## Warning: Removed 1 rows containing missing values (geom_point).
There is a surplus of Licensed and Company Owned Starbucks in North America, however in Europe and Asia there is a wider mixture between the four types of ownership.
twincities_metro <- get_stamenmap(
bbox = c(left = -94, bottom = 44.6, right = -92.4, top = 45.3),
maptype = "terrain",
zoom = 10)
## Source : http://tile.stamen.com/terrain/10/244/367.png
## Source : http://tile.stamen.com/terrain/10/245/367.png
## Source : http://tile.stamen.com/terrain/10/246/367.png
## Source : http://tile.stamen.com/terrain/10/247/367.png
## Source : http://tile.stamen.com/terrain/10/248/367.png
## Source : http://tile.stamen.com/terrain/10/249/367.png
## Source : http://tile.stamen.com/terrain/10/244/368.png
## Source : http://tile.stamen.com/terrain/10/245/368.png
## Source : http://tile.stamen.com/terrain/10/246/368.png
## Source : http://tile.stamen.com/terrain/10/247/368.png
## Source : http://tile.stamen.com/terrain/10/248/368.png
## Source : http://tile.stamen.com/terrain/10/249/368.png
## Source : http://tile.stamen.com/terrain/10/244/369.png
## Source : http://tile.stamen.com/terrain/10/245/369.png
## Source : http://tile.stamen.com/terrain/10/246/369.png
## Source : http://tile.stamen.com/terrain/10/247/369.png
## Source : http://tile.stamen.com/terrain/10/248/369.png
## Source : http://tile.stamen.com/terrain/10/249/369.png
ggmap(twincities_metro) +
geom_point(data = Starbucks,
aes(x = Longitude, y = Latitude),
alpha = .7,
size = 1.5,
color= "red") +
theme_map() +
ggtitle("Starbucks locations in the Twin Cities metro area")
## Warning: Removed 25448 rows containing missing values (geom_point).
#get_stamenmap(
#bbox = c(left = -94, bottom = 44.6, right = -92.4, top = 45.3),
#maptype = "terrain",
#zoom = 11)
#zoomed out and the city labels became blurry
#get_stamenmap(
#bbox = c(left = -94, bottom = 44.6, right = -92.4, top = 45.3),
#maptype = "terrain",
#zoom = 9)
#zoomed in and made the city labels very large
When I had the zoom at 11 it zoomed out and the labels got blurry, however when I had the zoom number at 9, it zoomed in and made the city labels very large.
get_stamenmap() in help and look at maptype). Include a map with one of the other map types.twincities_metro <- get_stamenmap(
bbox = c(left = -94, bottom = 44.6, right = -92.4, top = 45.3),
maptype = "toner-hybrid",
zoom = 10)
## Source : http://tile.stamen.com/toner-hybrid/10/244/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/245/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/246/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/247/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/248/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/249/367.png
## Source : http://tile.stamen.com/toner-hybrid/10/244/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/245/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/246/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/247/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/248/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/249/368.png
## Source : http://tile.stamen.com/toner-hybrid/10/244/369.png
## Source : http://tile.stamen.com/toner-hybrid/10/245/369.png
## Source : http://tile.stamen.com/toner-hybrid/10/246/369.png
## Source : http://tile.stamen.com/toner-hybrid/10/247/369.png
## Source : http://tile.stamen.com/toner-hybrid/10/248/369.png
## Source : http://tile.stamen.com/toner-hybrid/10/249/369.png
ggmap(twincities_metro) +
geom_point(data = Starbucks,
aes(x = Longitude, y = Latitude),
alpha = .7,
size = 1.5,
color= "red") +
theme_map()+
ggtitle("Starbucks locations in the Twin Cities metro area")
## Warning: Removed 25448 rows containing missing values (geom_point).
annotate() function (see ggplot2 cheatsheet).twincities_metro <- get_stamenmap(
bbox = c(left = -94, bottom = 44.6, right = -92.4, top = 45.3),
maptype = "toner-hybrid",
zoom = 10)
ggmap(twincities_metro) +
geom_point(data = Starbucks,
aes(x = Longitude, y = Latitude),
alpha = .5,
size = 1.5,
color= "blue") +
annotate("text", x=-93.1, y= 44.9, color="orange",
size=2.5, fontface= "bold", label= "Macalester") +
theme_map()+
ggtitle("Starbucks locations in the Twin Cities metro area")
## Warning: Removed 25448 rows containing missing values (geom_point).
geom_map())The example I showed in the tutorial did not account for population of each state in the map. In the code below, a new variable is created, starbucks_per_10000, that gives the number of Starbucks per 10,000 people. It is in the starbucks_with_2018_pop_est dataset.
census_pop_est_2018 <- read_csv("https://www.dropbox.com/s/6txwv3b4ng7pepe/us_census_2018_state_pop_est.csv?dl=1") %>%
separate(state, into = c("dot","state"), extra = "merge") %>%
select(-dot) %>%
mutate(state = str_to_lower(state))
##
## -- Column specification --------------------------------------------------------
## cols(
## state = col_character(),
## est_pop_2018 = col_double()
## )
starbucks_with_2018_pop_est <-
starbucks_us_by_state %>%
left_join(census_pop_est_2018,
by = c("state_name" = "state")) %>%
mutate(starbucks_per_10000 = (n/est_pop_2018)*10000)
dplyr review: Look through the code above and describe what each line of code does.The first line of code transfers the information from the read_cvs into the new dataset census_pop_est_2018. The following line of code separates the “.” from the state in the state column. The select function is calling the columns excluding the dot. Then the mutate function is transforming the state column to lowercase.
The second chunk of code is adding the data into the new dataset starbucks_with_2018_pop_est. The starbucks_us_by_state dataset is being merged with the census_pop_est_2018 dataset by the names of the states. Then the mutate function is calculating the amount of starbucks per 10000 population by diving the number of starbucks by the population in 2018 and multiplying by 10000.
states_map <- map_data("state")
starbucks_with_2018_pop_est %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = starbucks_per_10000),
opacity= 0.3) +
geom_point(data= Starbucks %>% filter(Country == "US",
!(`State/Province` %in% c("AK","HI"))),
aes(x=Longitude,
y=Latitude),
size= 0.2,
color="orange") +
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
scale_fill_gradient(low= "cyan", high= "darkblue") +
ggtitle("Number of Starbucks per 10,000 people in the United States") +
labs(caption="Created by Joselyn Angeles Figueroa")
## Warning: Ignoring unknown parameters: opacity
Based on this map, Starbucks locations are concentrated in larger states, mostly in the east and west coastlines.
leaflet)favmnplaces_joselyn <- tibble(
place= c("JS Bean Factory",
"Mattocks Park", "Janet Wallace",
"My Burger", "Mall of St. Paul", "Minnehaha Falls",
"Mississippi River", "Grand Ole Creamery",
"I like you too", "St. Paul Corner Drug",
"Kate's place", "Home"),
long= c(-93.16269, -93.1720466,
-93.17134,-93.16798, -93.1768303,-93.21257,
-93.20009, -93.1321013,-93.1669318,
-93.1654329, -93.16735,-93.1752715),
lat= c(44.92616, 44.9292636,
44.93814, 44.94055, 44.9468396, 44.91596,
44.94237, 44.939961, 44.929193,
44.9338354,44.93954,44.933149)) %>%
mutate(fav = ifelse (place %in% c(
"JS Bean Factory", "Grand Ole Creamery", "Mississippi River"),
"Top Three Favorites", "Favorites"))
favmnplaces_joselyn
pal <- colorFactor(c("#17A1F8","#F817D2"), favmnplaces_joselyn$fav)
leaflet(data = favmnplaces_joselyn) %>%
addProviderTiles("CartoDB.Voyager") %>%
addCircles(lng= ~long,
lat= ~lat,
label= ~place,
radius = 10,
opacity = 1,
color= ~pal(fav)) %>%
addLegend("topleft",
pal = pal,
values= ~fav,
opacity= 1) %>%
addPolylines(lng= ~long,
lat= ~lat,
color= col2hex("grey"))
Create a data set using the tibble() function that has 10-15 rows of your favorite places. The columns will be the name of the location, the latitude, the longitude, and a column that indicates if it is in your top 3 favorite locations or not. For an example of how to use tibble(), look at the favorite_stp_by_lisa I created in the data R code chunk at the beginning.
Create a leaflet map that uses circles to indicate your favorite places. Label them with the name of the place. Choose the base map you like best. Color your 3 favorite places differently than the ones that are not in your top 3 (HINT: colorFactor()). Add a legend that explains what the colors mean.
Connect all your locations together with a line in a meaningful way (you may need to order them differently in the original data).
If there are other variables you want to add that could enhance your plot, do that now.
This section will revisit some datasets we have used previously and bring in a mapping component.
The data come from Washington, DC and cover the last quarter of 2014.
Two data tables are available:
Trips contains records of individual rentalsStations gives the locations of the bike rental stationsHere is the code to read in the data. We do this a little differently than usually, which is why it is included here rather than at the top of this file. To avoid repeatedly re-reading the files, start the data import chunk with {r cache = TRUE} rather than the usual {r}. This code reads in the large dataset right away.
data_site <-
"https://www.macalester.edu/~dshuman1/data/112/2014-Q4-Trips-History-Data.rds"
Trips <- readRDS(gzcon(url(data_site)))
Stations<-read_csv("http://www.macalester.edu/~dshuman1/data/112/DC-Stations.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## name = col_character(),
## lat = col_double(),
## long = col_double(),
## nbBikes = col_double(),
## nbEmptyDocks = col_double()
## )
Stations to make a visualization of the total number of departures from each station in the Trips data. Use either color or size to show the variation in number of departures. This time, plot the points on top of a map. Use any of the mapping tools you’d like.washing_dc<-get_stamenmap(
bbox = c(left = -77.4220, bottom = 38.7155, right = -76.6077, top = 39.0720),
maptype = "terrain",
zoom = 11)
## Source : http://tile.stamen.com/terrain/11/583/782.png
## Source : http://tile.stamen.com/terrain/11/584/782.png
## Source : http://tile.stamen.com/terrain/11/585/782.png
## Source : http://tile.stamen.com/terrain/11/586/782.png
## Source : http://tile.stamen.com/terrain/11/587/782.png
## Source : http://tile.stamen.com/terrain/11/588/782.png
## Source : http://tile.stamen.com/terrain/11/583/783.png
## Source : http://tile.stamen.com/terrain/11/584/783.png
## Source : http://tile.stamen.com/terrain/11/585/783.png
## Source : http://tile.stamen.com/terrain/11/586/783.png
## Source : http://tile.stamen.com/terrain/11/587/783.png
## Source : http://tile.stamen.com/terrain/11/588/783.png
## Source : http://tile.stamen.com/terrain/11/583/784.png
## Source : http://tile.stamen.com/terrain/11/584/784.png
## Source : http://tile.stamen.com/terrain/11/585/784.png
## Source : http://tile.stamen.com/terrain/11/586/784.png
## Source : http://tile.stamen.com/terrain/11/587/784.png
## Source : http://tile.stamen.com/terrain/11/588/784.png
trips<-Trips %>%
left_join(Stations,
by = c("sstation"="name")) %>%
group_by(lat,long) %>%
summarize(departures = n())
## `summarise()` has grouped output by 'lat'. You can override using the `.groups` argument.
ggmap(washing_dc) +
geom_point(data = trips,
aes(x = long, y = lat,
color= departures)) +
theme_map()+
scale_color_gradient(low = "blue", high = "red") +
labs(title = "Map of Bike Departures from Stations in Washington D.C.",
x= "",
y="",
color="Departures") +
theme(legend.background = element_blank())
## Warning: Removed 22 rows containing missing values (geom_point).
washing_dc<-get_stamenmap(
bbox = c(left = -77.4220, bottom = 38.7155, right = -76.6077, top = 39.0720),
maptype = "terrain",
zoom = 11)
trips2<-Trips %>%
left_join(Stations,
by = c("sstation"="name")) %>%
group_by(lat,long) %>%
mutate(client_casual= client=="Casual") %>%
summarize(prop_casual = sum(client_casual)/n())
## `summarise()` has grouped output by 'lat'. You can override using the `.groups` argument.
ggmap(washing_dc) +
geom_point(data = trips2,
aes(x = long, y = lat,
color= prop_casual)) +
theme_map()+
labs(title = "Map of Bike Departures from Stations by Casual Clients in Washington D.C.",
x= "",
y="",
color="Proportion of Casual Clients") +
scale_color_gradient(low = "blue", high = "orange") +
theme(legend.background = element_blank())
## Warning: Removed 22 rows containing missing values (geom_point).
Rentals from casual clients tend to be clustered around the same area close to the center of the city area. They are less likely to get bike rentals outside of that area.
The following exercises will use the COVID-19 data from the NYT.
covid19_match <- covid19 %>%
group_by(cases) %>%
filter(date == "2021-02-18") %>%
count(state) %>%
mutate(state_name = str_to_lower(state))
covid19_match
states_map <- map_data("state")
covid19_match %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = cases)) +
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
scale_fill_gradient(low= "cyan", high= "royalblue") +
ggtitle("Most recent number of COVID-19 cases in the United States")+
labs(fill="Cases")
This data neglects to consider the size of the population which means that states with higher populations, and more likelihood of having higher cumulative cases, are misrepresented as being worse than other states.
covid19_2018_pop <-
covid19_match %>%
left_join(census_pop_est_2018,
by = c("state_name" = "state")) %>%
mutate(covid19_10000 = (cases/est_pop_2018)*10000)
states_map <- map_data("state")
covid19_2018_pop %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = covid19_10000)) +
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
scale_fill_gradient(low= "cyan", high= "royalblue") +
ggtitle("Most recent cumulative COVID cases per 10,000 people in the United States")+
labs(fill= "Proportion per 10000")
covid19_multiple <- covid19 %>%
filter(date %in% c(ymd("2020-03-19", "2020-07-14", "2020-11-01","2021-02-18"))) %>%
mutate(state_name = str_to_lower(state))
covid19_multiple_2018_pop <-
covid19_multiple %>%
left_join(census_pop_est_2018,
by = c("state_name" = "state")) %>%
mutate(covid19_10000 = (cases/est_pop_2018)*10000)
states_map <- map_data("state")
covid19_multiple_2018_pop %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = covid19_10000)) +
facet_wrap(vars(date)) +
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
scale_fill_gradient(low= "cyan", high= "royalblue") +
theme(legend.background = element_blank())+
labs(fill= "Proportion per 10000")+
ggtitle("Cumulative COVID cases per 10,000 people in the United States over time")
The United States as a whole has cumulatively increased in COVID cases, however there are specific states where the proportion of cumulative cases are worse, such as North and South Dakota.
These exercises use the datasets MplsStops and MplsDemo from the carData library. Search for them in Help to find out more information.
MplsStops dataset to find out how many stops there were for each neighborhood and the proportion of stops that were for a suspicious vehicle or person. Sort the results from most to least number of stops. Save this as a dataset called mpls_suspicious and display the table.mpls_suspicious <-MplsStops %>%
group_by(neighborhood, problem) %>%
summarize(nprob= n()) %>%
mutate(n_neigh= sum(nprob),
prop_sus= nprob/n_neigh) %>%
arrange(desc(n_neigh))
## `summarise()` has grouped output by 'neighborhood'. You can override using the `.groups` argument.
mpls_suspicious
#I tried for a really long time to figure out how to include the lat/long
#without messing up the rest of the code and it just wasn't happening :(
leaflet map and the MplsStops dataset to display each of the stops on a map as a small point. Color the points differently depending on whether they were for suspicious vehicle/person or a traffic stop (the problem variable). HINTS: use addCircleMarkers, set stroke = FAlSE, use colorFactor() to create a palette.pal <- colorFactor(c("#E02D1B","#0A0100"),
domain= MplsStops$problem)
pal
## function (x)
## {
## if (length(x) == 0 || all(is.na(x))) {
## return(rep.int(na.color, length(x)))
## }
## lvls <- getLevels(domain, x, lvls, ordered)
## pf <- safePaletteFunc(palette, na.color, alpha, nlevels = length(lvls) *
## ifelse(reverse, -1, 1))
## origNa <- is.na(x)
## x <- match(as.character(x), lvls)
## if (any(is.na(x) != origNa)) {
## warning("Some values were outside the color scale and will be treated as NA")
## }
## scaled <- scales::rescale(as.integer(x), from = c(1, length(lvls)))
## if (any(scaled < 0 | scaled > 1, na.rm = TRUE)) {
## warning("Some values were outside the color scale and will be treated as NA")
## }
## if (reverse) {
## scaled <- 1 - scaled
## }
## pf(scaled)
## }
## <bytecode: 0x00000000241abb10>
## <environment: 0x0000000029e3f780>
## attr(,"colorType")
## [1] "factor"
## attr(,"colorArgs")
## attr(,"colorArgs")$na.color
## [1] "#808080"
leaflet(data= MplsStops) %>%
addProviderTiles("CartoDB.Voyager") %>%
addMarkers(lng= ~long,
lat= ~lat,
label= ~neighborhood) %>%
#opacity = .5,
#weight= .2,
#color= ~pal(problem),
#stroke= FALSE) %>%
addLegend("topleft",
pal = pal,
values= ~problem,
opacity= 1,
title= "Problem")
eval=FALSE. Although it looks like it only links to the .sph file, you need the entire folder of files to create the mpls_nbhd data set. These data contain information about the geometries of the Minneapolis neighborhoods. Using the mpls_nbhd dataset as the base file, join the mpls_suspicious and MplsDemo datasets to it by neighborhood (careful, they are named different things in the different files). Call this new dataset mpls_all.mpls_nbhd <- st_read("Minneapolis_Neighborhoods-20210220/Minneapolis_Neighborhoods.shp", quiet = TRUE)
mpls_all<-mpls_nbhd %>%
left_join(mpls_suspicious,
by = c("BDNAME" = "neighborhood")) %>%
left_join(MplsStops,
by = c("BDNAME" = "neighborhood")) %>%
left_join(MplsDemo,
by = c("BDNAME" = "neighborhood"))
leaflet to create a map from the mpls_all data that colors the neighborhoods by prop_suspicious. Display the neighborhood name as you scroll over it. Describe what you observe in the map.leaflet(data= mpls_all) %>%
addProviderTiles("CartoDB.Voyager") %>%
addCircleMarkers(lng= ~long,
lat= ~lat,
label= ~BDNAME,
opacity = .5,
weight= .2,
color= ~pal(prop_sus),
stroke= FALSE) %>%
addLegend("topleft",
pal = pal,
values= ~prop_sus,
opacity= 1)
## Warning in validateCoords(lng, lat, funcName): Data contains 1 rows with either
## missing or invalid lat/lon values and will be ignored
## Warning in pal(prop_sus): Some values were outside the color scale and will be
## treated as NA
## Warning in pal(prop_sus): Some values were outside the color scale and will be
## treated as NA
## Warning in pal(v): Some values were outside the color scale and will be treated
## as NA
#Note: :(
leaflet to create a map of your own choosing. Come up with a question you want to try to answer and use the map to help answer that question. Describe what your map shows.DemoStops<-MplsStops %>%
left_join(MplsDemo,
by = "neighborhood")
leaflet(data=DemoStops) %>%
addProviderTiles("CartoDB.Voyager") %>%
addCircleMarkers(lng= ~long,
lat= ~lat,
label= ~neighborhood,
opacity = .5,
weight= .2,
color= ~pal(problem),
stroke= FALSE) %>%
addLegend("topleft",
pal = pal,
values= ~problem,
opacity= 1,
title= "Problem")
DID YOU REMEMBER TO UNCOMMENT THE OPTIONS AT THE TOP?